// 以数组为例，测试高阶函数

let arr = [] ;

console.log( arr.length );
arr.push( '朱某红' );
console.log( arr.length );
arr.push( '常仡' );
console.log( arr.length );
arr.push( '张玉洁' , '赵婷' , '郑娅婷' , '马俊珍' );
console.log( arr.length );
console.log( arr );

console.log( '- - - '.repeat(10) );

// 遍历数组
for (let index = 0; index < arr.length; index++) {
    const element = arr[index];
    console.log( element );
}

console.log( '- - - '.repeat(10) );

for (const index in arr) {
    const element = arr[index];
    console.log( element );
}

console.log( '- - - '.repeat(10) );

let fn = function(element,index,array) {
    console.log( element , index , array == arr );
}

// 用 Array.prototype.forEach 函数遍历数组
arr.forEach( fn );

Array.prototype.myForEach = function( operate ){
    const array = this ;
    for( let index = 0 ; index < array.length ; index++ ){
        let element = array[ index ];
        console.log( `调用${operate.name}函数` );
        operate(element,index,array);
    }
}

arr.myForEach( fn );